#ifndef _LIST_H_
#define _LIST_H_

#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include "myhead.h"

typedef struct doublelist
{
    // 数据域
    char name[50];                // 商品名字
    double price;                 // 商品价格
    int stock;                    // 商品库存
    char ver_name[50];            // 图片名字
    lv_obj_t * btn;               // 商品对应的按钮
    lv_obj_t * btn1;              // 管理员界面按钮
    const lv_img_dsc_t * img_dsc; // 商品对应图片
    // 指针域
    struct doublelist * next; // 指向后一个节点
    struct doublelist * prev; // 指向前一个节点
} dlist;

typedef struct purchaselist
{
    char name[50];   // 商品名称
    double price;    // 单价
    int count;       // 数量
    double subtotal; // 小计金额
    lv_obj_t * btn;  // 商品对应的删除按钮

    struct purchaselist * next; // 指向后一个节点
    struct purchaselist * prev; // 指向前一个节点
} plist;

extern struct doublelist * list_init();
extern int list_insert_tail(char * name, double price, int stock, char * ver_name, lv_obj_t * btn,
                            const lv_img_dsc_t * img_dsc, struct doublelist * head);
extern int list_delete(char * name, struct doublelist * head);
extern int list_search(char * name, struct doublelist * head);
extern int list_pri(struct doublelist * head);
extern int list_change(char * name, int stock, dlist * head);
extern int list_des(struct doublelist * head);

extern struct purchaselist * plist_init();
extern int plist_insert_tail(char * name, double price, int count, lv_obj_t * btn, plist * head);
extern int plist_delete(char * name, plist * head);
extern int plist_search(char * name, plist * head);
extern int plist_pri(plist * head);
extern int plist_change(char * name, int count, plist * head);
extern int plist_change1(char * name, int count, plist * head);
extern int plist_des(plist * head);

#endif